package com.yrmao.chiefenergyofficer.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yrmao.chiefenergyofficer.R;
import com.yrmao.chiefenergyofficer.ui.common.BaseFragment;
import com.yrmao.chiefenergyofficer.ui.fragment.itemcontent.ContentPageAdapter;
import com.yrmao.chiefenergyofficer.ui.modle.GridviewContentInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sikong on 16/11/16.
 */

public class ItemContentFragment extends BaseFragment {
    private View mContentView;
    private ViewPager viewpager_content;
    private List<GridviewContentInfo> listContent;
    private int[] image = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,};
    private String[] content = {"红包助手", "地图", "公交线路", "待定1", "待定2", "待定3"};
    private String[] imageUrl = {"", "", "", "", "", "",};
    private int pagesize = 4;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContentView = LayoutInflater.from(getActivity()).inflate(R.layout.frag_content, null);
        initData();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return mContentView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initview();
    }

    private void initview() {
        viewpager_content = (ViewPager) getActivity().findViewById(R.id.viewpager_content);

        ContentPageAdapter mAdapter = new ContentPageAdapter(listContent, pagesize, getActivity());
        viewpager_content.setAdapter(mAdapter);
    }

    private void initData() {
        listContent = new ArrayList<>();
        GridviewContentInfo info;
        for (int i = 0; i < image.length; i++) {
            info = new GridviewContentInfo();
            info.setMainContentInfo(image[i], imageUrl[i], content[i]);
            listContent.add(info);
        }

    }

}
